<!-- 功能包管理 -->
<template>
  <div class="table">
    <dt-grid ref="tableRef" :onFetch="onFetch" page>
      <template #btn>
        <div class="flex">
          <Button type="primary" @click="create">新建功能包</Button>
        </div>
      </template>
    </dt-grid>
  </div>
  <edit-modal ref="editRef" @success="onSuccess" />
  <check-modal ref="checkRef" />
</template>

<script setup>
  import { ref, onMounted } from 'vue'
  import dt from '@dt/dt'
  import apiMgr from '../biz/index.js'
  import { listOpt } from '../opt/columns.js'
  import editModal from '../component/editModal.vue'
  import checkModal from '../component/checkModal.vue'

  const [tableRef, editRef, checkRef] = [ref(), ref(), ref()]
  onMounted(() => {
    tableRef.value.init(new listOpt(fn))
    tableRef.value.fetch()
  })
  function onSuccess() {
    tableRef.value.fetch()
  }
  const fn = {
    //查看
    toView: (data) => {
      data.packName = '11111'
      checkRef.value.show(data)
    },
    editFun: (data) => {
      editRef.value.edit(data)
    },
    syncFun: (data) => {
      dt.ui.Modal.confirm({
        title: `提示`,
        content: `是否将该功能包最新功能权限生效?`,
        onOk: () => {
          let params = {
            id: data.id
          }
          apiMgr.pakeSync(params).then((res) => {
            dt.ui.Message.success('同步成功')
            tableRef.value.fetch()
          })
        }
      })
    }
  }
  function create(data) {
    editRef.value.add()
  }
  function onFetch(obj) {
    let params = {
      ...obj
    }
    return apiMgr.getPackList(params).then((res) => {
      return res
    })
  }
</script>

<style scoped lang="scss"></style>
